{% extends "base.html" %}

{% block main-page %}
    <div><p>Support REST</p></div>
    <div>
        <h2>REST</h2>
        <p>The endpoint is {{site_settings.host_site}}/apis/rest/</p>
        <p>example:
<pre class="codehl" lang="python" hlstyle="native">
import urllib2
from oauth_utils import OAuthRequest, OAuthConsumer
consumer = OAuthConsumer('73fe97f470f64a25870caaa2de5618a5',
                         '0ccf79a2268a4eacacdbe5006e0cfd39')
rest_url = "{{site_settings.host_site}}/apis/rest/"

def send_rest(parameters, http_method='POST'):
    request = OAuthRequest.from_consumer(consumer=consumer,http_url=rest_url,
                                         http_method=http_method,parameters=parameters)

    request.sign_request(consumer)
    if http_method == "POST":
        print("Post to %s"%rest_url)
        urllib2_request = urllib2.Request(rest_url,request.to_postdata())
    else:
        print("Get %s"%request.to_fullurl())
        urllib2_request = urllib2.Request(request.to_fullurl())

    result = urllib2.urlopen(urllib2_request)
    print result.read()
    result.close()

parameters = {'method': 'get_methods'}
send_rest(parameters, http_method='POST')
send_rest(parameters, http_method='GET')
</pre>
    </p>
    </div>

    <!--div>
        <h2>XMLRPC</h2>
        <p>The endpoint is {{site_settings.host_site}}/apis/rpc2/</p>
        <p>example:
<pre class="codehl" lang="python" hlstyle="native">
from xmlrpclib import ServerProxy, Error
from oauth_utils import OAuthRequest, OAuthConsumer

xmlrpc_url = "{{site_settings.host_site}}/apis/rpc2/"
server = ServerProxy(xmlrpc_url)
print server
consumer = OAuthConsumer('73fe97f470f64a25870caaa2de5618a5',
                         '0ccf79a2268a4eacacdbe5006e0cfd39')
request = OAuthRequest.from_consumer(consumer=consumer,
                                     http_url=xmlrpc_url,
                                     http_method="POST")
request.sign_request(consumer)
oauth = request.to_xmlrpc_dict()
try:
    print server.get_methods(oauth)
    print server.get_method_info('photo_read',oauth)
    print server.get_method_info('photo_write',oauth)
    print server.get_method_info('photo_delete',oauth)
    print server.photo_write(123, 'param2', oauth)
except Error, v:
    print "ERROR", v
</pre>
    </p>
    </div-->

{% endblock %}
